package com.ys.service.hr.impl;

import com.alibaba.fastjson.JSON;
import com.ys.constant.AppConstant;
import com.ys.dto.AddDto;
import com.ys.entity.base.TbBaseInfoArea;
import com.ys.entity.base.TbFileInfo;
import com.ys.entity.flow.YspModel;
import com.ys.entity.hr.ThrUserArchives;
import com.ys.entity.hr.ThrUserEntryApply;
import com.ys.entity.hr.ThrUserIdCardPhoto;
import com.ys.entity.sys.*;
import com.ys.enume.flow.FlowEnum;
import com.ys.enume.flow.YsProcInstEnum;
import com.ys.mapper.hr.HrMapper;
import com.ys.mapper.hr.ThrUserEntryApplyMapper;
import com.ys.mapper.hr.ThrUserIdCardPhotoMapper;
import com.ys.service.business.TbFileInfoService;
import com.ys.service.flow.YspTaskService;
import com.ys.service.hr.ThrUserArchivesService;
import com.ys.service.hr.ThrUserEntryApplyService;
import com.ys.service.sys.TsUserInfoService;
import com.ys.util.CheckUtil;
import com.ys.util.DateUtil;
import com.ys.util.RedisUtil;
import com.ys.util.dh.DhPassUtil;
import com.ys.util.shiro.ShiroUtils;
import com.ys.vo.Flow;
import com.ys.vo.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

/**
 * 员工入职申请
 */
@Service("thrUserEntryApply")
public class ThrUserEntryApplyServiceImpl implements ThrUserEntryApplyService {
	private static final Logger logger = LoggerFactory.getLogger(ThrUserEntryApplyServiceImpl.class);

	@Autowired
	private ThrUserEntryApplyMapper thrUserEntryApplyMapper;

	@Autowired
	private ThrUserIdCardPhotoMapper thrUserIdCardPhotoMapper;

	@Autowired
	private HrMapper hrMapper;

	@Autowired
	private YspTaskService yspTaskService;

	@Autowired
	private CheckUtil checkUtil;

	@Autowired
	private ThrUserArchivesService thrUserArchivesService;

	@Autowired
	private TsUserInfoService tsUserInfoService;

	@Autowired
	private RedisUtil redisUtil;

	@Autowired
	private TbFileInfoService tbFileInfoService;

	/**
	 * 新增
	 */
	@Override
	public R add(Map<String, Object> params, Long menuId) throws Exception{
		logger.info("员工入职申请新增传参:"+params);
		//参数验证
		String errorBack = checkParams(params, menuId);
		if(errorBack!=null && !"".equals(errorBack)){
			return R.error(errorBack);
		}
		params.put("roleIdAttribute",0);//默认职能
		ThrUserEntryApply thrUserEntryApply = JSON.parseObject(JSON.toJSONString(params), ThrUserEntryApply.class);
		thrUserEntryApply.setStatus(1);//状态
		thrUserEntryApply.setEffectStock(0);//审批状态
		//获取用户UserId
		Map<String, Object> maxUserIdMap = hrMapper.getMaxUserId();
		String userIdStr = maxUserIdMap.get("maxUserId").toString();
		String userId = null;
		int userIdInt = Integer.parseInt(userIdStr);
		if(userIdInt==99999){
			userId = "000001";
		}else {
			userIdInt ++ ;
			//补0
			userId = String.format("%0"+5+"d", userIdInt);
		}
		thrUserEntryApply.setUserId(userId);

		//获取制单人信息
		TsUserChange tsUserChange = new TsUserChange().setUserId(ShiroUtils.getUserId()).setOrderby("A.CreateTime DESC").queryFirst();
		if(tsUserChange!=null){
			thrUserEntryApply.setCreateChangeId(tsUserChange.getId());//制单人变更信息
		}else {
			R.error("未查询到制单人信息！");
		}
		//新增员工入职申请
		thrUserEntryApplyMapper.insert(thrUserEntryApply);
		//循环新增员工身份证照片信息表
		for(int i =1 ;i<=3;i++){
			if(params.get("userPhoto"+i)!=null || params.get("idCardfront"+i)!=null || params.get("idCardBack"+i)!=null ||
					!"".equals(params.get("userPhoto"+i)) || !"".equals(params.get("idCardfront"+i)) || !"".equals(params.get("idCardBack"+i)) ){
				ThrUserIdCardPhoto thrUserIdCardPhoto = new ThrUserIdCardPhoto();
				thrUserIdCardPhoto.setUserId(thrUserEntryApply.getUserId());
				thrUserIdCardPhoto.setStatus(1);
				if(params.get("userPhoto"+i)!=null){
					thrUserIdCardPhoto.setUserPhoto(params.get("userPhoto"+i).toString());
				}
				if(params.get("idCardfront"+i)!=null){
					thrUserIdCardPhoto.setIdCardfront(params.get("idCardBack"+i).toString());
				}
				if(params.get("idCardBack"+i)!=null){
					thrUserIdCardPhoto.setIdCardBack(params.get("idCardBack"+i).toString());
				}
				//新增员工身份证照片信息表
				thrUserIdCardPhotoMapper.insert(thrUserIdCardPhoto);
			}
		}

		YsMenu ysMenu = new YsMenu().setId(menuId).queryFirst();
		if (ysMenu.getFlowModelId().longValue() != 0L) {
			YspModel yspModel = new YspModel().setId(ysMenu.getFlowModelId()).queryFirst();
			String codeModel = yspModel.getCode();
			String createUserId = ShiroUtils.getUserId();
			yspTaskService.init(codeModel, thrUserEntryApply.getBid(), createUserId);
		}
		return R.ok(AddDto.gotoEdit("/web/hr/thrUserEntryApply/toEdit?bid=" + thrUserEntryApply.getBid()));
	}

	/**
	 * 修改
	 */
	@Override
	public R update(Map<String, Object> params, Long menuId) throws Exception{
		logger.info("员工入职申请修改传参:"+params);
		//参数验证
		String errorBack = checkParams(params, menuId);
		if(errorBack!=null && !"".equals(errorBack)){
			return R.error(errorBack);
		}
		params.put("roleIdAttribute",0);//默认职能
		ThrUserEntryApply thrUserEntryApply = JSON.parseObject(JSON.toJSONString(params), ThrUserEntryApply.class);
		// 验证状态
		YsProcInst ysProcInst = new YsProcInst().setBid(thrUserEntryApply.getBid()).queryFirst();
		if (ysProcInst == null) {
			return R.error("审批数据不存在，无法编辑");
		} else if (ysProcInst.getStateFlow() != YsProcInstEnum.StateFlow.INIT.value) {
			return R.error("已流转，无法编辑");
		}
		//删除员工身份证照片信息表
		hrMapper.deleteUserIdCardPhotoByUserId(thrUserEntryApply.getUserId());
		//循环新增员工身份证照片信息表
		for(int i =1 ;i<=3;i++){
			if(params.get("userPhoto"+i)!=null || params.get("idCardfront"+i)!=null || params.get("idCardBack"+i)!=null ||
					!"".equals(params.get("userPhoto"+i)) || !"".equals(params.get("idCardfront"+i)) || !"".equals(params.get("idCardBack"+i)) ){
				ThrUserIdCardPhoto thrUserIdCardPhoto = new ThrUserIdCardPhoto();
				thrUserIdCardPhoto.setUserId(thrUserEntryApply.getUserId());
				thrUserIdCardPhoto.setStatus(1);
				if(params.get("userPhoto"+i)!=null){
					thrUserIdCardPhoto.setUserPhoto(params.get("userPhoto"+i).toString());
				}
				if(params.get("idCardfront"+i)!=null){
					thrUserIdCardPhoto.setIdCardfront(params.get("idCardBack"+i).toString());
				}
				if(params.get("idCardBack"+i)!=null){
					thrUserIdCardPhoto.setIdCardBack(params.get("idCardBack"+i).toString());
				}
				//新增员工身份证照片信息表
				thrUserIdCardPhotoMapper.insert(thrUserIdCardPhoto);
			}
		}
		thrUserEntryApplyMapper.update(thrUserEntryApply);
		return R.ok(AddDto.noAction());
	}


	//删除
	@Override
	@Transactional
	public R del(Long id) throws Exception{
		if (id == null) {
			return R.error("ID不能为空");
		}
		ThrUserEntryApply entity = new ThrUserEntryApply().setId(id).queryFirst();
		if (entity.getEffectStock() == FlowEnum.EffectStock.EFFECTED.value) {
			return R.error("已生效数据无法删除");
		}
		// 验证是否制单人
		String loginUserId = ShiroUtils.getUserId();
		TsUserChange tsUserChange = new TsUserChange().setId(entity.getCreateChangeId()).queryFirst();
		if (!tsUserChange.getUserId().equals(loginUserId) && !"admin".equals(loginUserId)) {
			return R.error("非制单人，无法删除");
		}
		//删除照片列表信息
		hrMapper.delThrUserIdCardPhotoByUserId(entity.getUserId());
		//删除
		thrUserEntryApplyMapper.deleteTrue(id);
		//删除流程
		yspTaskService.flowDelete(entity.getBid(), loginUserId);
		return R.ok();
	}


	/**
	 * 流转通过
	 */
	@Override
	@Transactional
	public R flowPass(Long id, String loginUserId) throws Exception {

		ThrUserEntryApply entity = new ThrUserEntryApply().setId(id).queryFirst();
		Flow f = yspTaskService.flowPass(entity.getBid(), loginUserId);
		if (f.getCode() == Flow.Code.FAILED.value) {
			return R.error(f.getMsg());
		} else {
			if (f.getState() == Flow.State.FINISH.value) {
				flowFinish(entity.getBid());
			}
			return R.ok();
		}
	}

	/**
	 * 流转结束
	 */
	@Override
	@Transactional
	public void flowFinish(String bid) throws Exception {

		ThrUserEntryApply entity = new ThrUserEntryApply().setBid(bid).queryFirst();
		YsProcInst ysProcInst = new YsProcInst().setBid(entity.getBid()).queryFirst();
		if (ysProcInst.getStateFlow() != YsProcInstEnum.StateFlow.FINISH.value) {
			return;
		}
		Date theDate = new Date();
		entity.setEffectStock(FlowEnum.EffectStock.EFFECTED.value);
		entity.setUpdateTime(theDate);

		//时间
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");

		//获取用户对应的组织信息
		TsOrganizationInfo tsOrganizationInfo = new TsOrganizationInfo().setOrgid(entity.getDeptId().toString()).queryFirst();
		//获取用户对应的角色（岗位）信息
		YsRole ysRole = new YsRole().setId(entity.getRoleId()).queryFirst();
		//根据行政编码获取城市名称
		TbBaseInfoArea tbBaseInfoAreaByCity = null;
		if(entity.getWorkCity()!=null){
			tbBaseInfoAreaByCity = new TbBaseInfoArea().setCode(entity.getWorkCity()).queryFirst();
		}
		TbBaseInfoArea tbBaseInfoAreaByJg = null;
		if(entity.getNativePlace()!=null){
			tbBaseInfoAreaByJg = new TbBaseInfoArea().setCode(entity.getNativePlace()).queryFirst();
		}
		//默认密码
		String passWord = "123456";

		//*************************更新员工信息表*************************
		Map<String, Object> paramsByUserInfo = new HashMap<>();
		paramsByUserInfo.put("userId",entity.getUserId());//用户工号
		paramsByUserInfo.put("userName",entity.getUserName());//用户名字
		//获取加密密码
		String passEncrypt = DhPassUtil.encryptPassword(entity.getUserId(), passWord, AppConstant.PASSWORD_SALT);
		paramsByUserInfo.put("userPassWord",passEncrypt);//密码
		paramsByUserInfo.put("userPassWord2",passEncrypt);//密码
		paramsByUserInfo.put("userState","在职");//在职、离职状态
		paramsByUserInfo.put("userSex",(entity.getUserSex()==0?"女":"男"));//性别
		paramsByUserInfo.put("userSchooled",entity.getGraduationSchool());//毕业学校
		Date date = formatter.parse(entity.getBirthday());//时间类型转换
		paramsByUserInfo.put("userBirthday",date);//生日
		paramsByUserInfo.put("userCity",tbBaseInfoAreaByJg!=null?tbBaseInfoAreaByJg.getName():null);//城市名称
		paramsByUserInfo.put("userAddress",entity.getAddress());//详细地址
		paramsByUserInfo.put("userPhone1",entity.getTelephone());//电话1
		paramsByUserInfo.put("userLeader",entity.getHeadUserId());//上级用户工号
		paramsByUserInfo.put("organizationid",tsOrganizationInfo!=null?tsOrganizationInfo.getGuid():null);//组织IdUserBindRole
		paramsByUserInfo.put("disabled",0);//在职状态(在职0、离职1)
		paramsByUserInfo.put("cid",tsOrganizationInfo!=null?tsOrganizationInfo.getCid():null);//公司
		paramsByUserInfo.put("cidName",tsOrganizationInfo!=null?tsOrganizationInfo.getCidName():null);//公司名称
		paramsByUserInfo.put("orgId",tsOrganizationInfo!=null?tsOrganizationInfo.getId():null);//所属组织机构ID
		paramsByUserInfo.put("deptId",entity.getDeptId());//部门Id
		paramsByUserInfo.put("deptName",tsOrganizationInfo!=null?tsOrganizationInfo.getDeptName():null);//部门名字
		paramsByUserInfo.put("deptPath",tsOrganizationInfo!=null?tsOrganizationInfo.getDeptPath():null);//部门Id路径
		paramsByUserInfo.put("deptPathName",tsOrganizationInfo!=null?tsOrganizationInfo.getDeptPathName():null);//部门名字路径
		paramsByUserInfo.put("userType",(entity.getRoleIdAttribute()==0?"职能":"运营"));//岗位属性(0职能、1运营)
		paramsByUserInfo.put("userJg",tbBaseInfoAreaByJg!=null?tbBaseInfoAreaByJg.getName():null);//籍贯
		paramsByUserInfo.put("vBgs",tbBaseInfoAreaByCity.getName());//工作地址
		paramsByUserInfo.put("roleId",ysRole!=null?ysRole.getId():null);//角色Id
		paramsByUserInfo.put("roleName",ysRole!=null?ysRole.getName():null);//角色名称
		paramsByUserInfo.put("stateReimburseReward","0");//报销奖励状态，0未奖励1已奖励
		paramsByUserInfo.put("sourceType",3);//用户来源（1直接新增，2运营人新增，3职能入职）
		paramsByUserInfo.put("status","1");
		paramsByUserInfo.put("dRzSj",entity.getEntryDate()!=null?formatter.parse(entity.getEntryDate()):null);//入职时间
		paramsByUserInfo.put("dZzSj",entity.getFormalDate()!=null?formatter.parse(entity.getFormalDate()):null);//转正时间
		// 同步1.0岗位
		TsRoleInfo tsRoleInfo = new TsRoleInfo().setRoleName(ysRole.getName()).queryFirst();
		paramsByUserInfo.put("positionGuid",tsRoleInfo.getGuid());

		R isAddUserInfo = tsUserInfoService.addByNew(paramsByUserInfo);
		if(isAddUserInfo.getCode()==1){//失败
			//return R.error(R.getMsg());
			return;
		}
		//*************************更新员工档案信息*************************
		Map<String, Object> paramsByUserArchives = new HashMap<>();
		int num = 0;
		//设置档案编码（格式：YGDA年月日三位序号）
		if(redisUtil.get("thrUserArchivesBid")!= null && !"".equals(redisUtil.get("ThrUserArchivesBid"))){
			num = Integer.parseInt(redisUtil.get("thrUserArchivesBid"))+1;
		}
		redisUtil.set("thrUserArchivesBid",num+"");//加一更新
		LocalDateTime midnight = LocalDateTime.now().plusDays(1).withHour(0).withMinute(0).withSecond(0).withNano(0);
		long seconds = ChronoUnit.SECONDS.between(LocalDateTime.now(), midnight);
		redisUtil.setEx("thrUserArchivesBid",num+"",seconds, TimeUnit.SECONDS);//设置过期时间
		//设置档案编码（格式：YGDA年月日三位序号）
		String archivesBid = "YGDA"+DateUtil.getYYYYMMDD(theDate)+String.format("%0"+3+"d", num);
		//入参
		paramsByUserArchives.put("archivesBid",archivesBid);//档案编码（格式：YGDA年月日三位序号）
		paramsByUserArchives.put("userId",entity.getUserId());//用户工号
		paramsByUserArchives.put("userName",entity.getUserName());//用户名字
		paramsByUserArchives.put("userSex",entity.getUserSex());//性别
		paramsByUserArchives.put("birthday",entity.getBirthday());//生日
		paramsByUserArchives.put("nativePlace",entity.getNativePlace());//籍贯
		paramsByUserArchives.put("education",entity.getEducation());//学历
		paramsByUserArchives.put("graduationDate",entity.getGraduationDate());//毕业日期(YYYY-MM-DD)
		paramsByUserArchives.put("graduationSchool",entity.getGraduationSchool());//毕业学校
		paramsByUserArchives.put("major",entity.getMajor());//主修专业
		paramsByUserArchives.put("telephone",entity.getTelephone());//联系电话
		paramsByUserArchives.put("address",entity.getAddress());//居住地址
		paramsByUserArchives.put("workCity",entity.getWorkCity());//工作城市
		paramsByUserArchives.put("roleId",entity.getRoleId());//岗位
		paramsByUserArchives.put("roleIdAttribute",entity.getRoleIdAttribute());//岗位属性
		paramsByUserArchives.put("deptId",entity.getDeptId());//部门
		paramsByUserArchives.put("headUserId",entity.getHeadUserId());//上级用户工号
		paramsByUserArchives.put("belongCompany",entity.getBelongCompany());//所属公司
		paramsByUserArchives.put("graduationCertificate",entity.getGraduationCertificate());//毕业证书附件路径
		paramsByUserArchives.put("educationCertificate",entity.getEducationCertificate());//学历证书附件路径
		paramsByUserArchives.put("laborContract",entity.getLaborContract());//劳动合同附件路径
		paramsByUserArchives.put("otherFile",entity.getOtherFile());//其他附件路径
		paramsByUserArchives.put("remark",entity.getRemark());//备注
		paramsByUserArchives.put("userState",entity.getUserState());//员工状态（0实习、1试用、2正式）
		paramsByUserArchives.put("entryDate",entity.getEntryDate());//入职时间
		paramsByUserArchives.put("formalDate",entity.getFormalDate());//转正时间
		paramsByUserArchives.put("officeId",entity.getOfficeId());//办公室Id
		paramsByUserArchives.put("idCard",entity.getIdCard());//身份证号码
		ThrUserArchives thrUserArchives = thrUserArchivesService.add(paramsByUserArchives);
		long archivesId = thrUserArchives.getId();

		//同步附件信息至档案表
		List<TbFileInfo> tbFileInfoList = new TbFileInfo().setSourceId(entity.getId()).where("A.SourceType IN (8,9,10,11)").queryList();
		if(tbFileInfoList!=null && tbFileInfoList.size()>0){
			//毕业证书附件
			List<TbFileInfo> tbFileInfoByGraduation = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("graduationCertificate")).collect(Collectors.toList());
			if(tbFileInfoByGraduation.size()>0){
				for(TbFileInfo item:tbFileInfoByGraduation){
					item.setSourceId(archivesId);
					item.setSourceType(3);
					tbFileInfoService.add(item);
				}
			}
			//学历证书附件
			List<TbFileInfo> tbFileInfoByEducation = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("educationCertificate")).collect(Collectors.toList());
			if(tbFileInfoByEducation.size()>0){
				for(TbFileInfo item:tbFileInfoByEducation){
					item.setSourceId(archivesId);
					item.setSourceType(4);
					tbFileInfoService.add(item);
				}
			}
			//劳动合同附件
			List<TbFileInfo> tbFileInfoByLaborContract = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("laborContract")).collect(Collectors.toList());
			if(tbFileInfoByLaborContract.size()>0){
				for(TbFileInfo item:tbFileInfoByLaborContract){
					item.setSourceId(archivesId);
					item.setSourceType(5);
					tbFileInfoService.add(item);
				}
			}
			//其他附件
			List<TbFileInfo> tbFileInfoByOtherFile = tbFileInfoList.stream().filter(item->item.getSourceCode().equals("otherFile")).collect(Collectors.toList());
			if(tbFileInfoByOtherFile.size()>0){
				for(TbFileInfo item:tbFileInfoByOtherFile){
					item.setSourceId(archivesId);
					item.setSourceType(6);
					tbFileInfoService.add(item);
				}
			}
		}

		//修改信息
		thrUserEntryApplyMapper.update(entity);


	}



	/**
	 * 参数验证
	 */
	@Override
	@Transactional
	public String checkParams(Map<String, Object> params, Long menuId) throws Exception {
		//获取pc字段数据
		List<YsCol> listField = new YsCol()
				.where("A.MenuId = "+menuId)
				.setOrderby("A.SortNo ASC")
				.queryList();
		//验证必填字段的非空；其他字段的长度限制、类型
		String backMsg = checkUtil.checkTableColLengthAndDataType("THR_UserEntryApply",listField,params,ysColItem->ysColItem.getFormEditRequired()!=null && ysColItem.getFormEditRequired() == 1);
		if(checkUtil.isNotNullByObject(params.get("telephone")) && !checkUtil.isPhone(params.get("telephone").toString())){
			backMsg = "手机号格式有误！";
		}
		if(checkUtil.isNotNullByObject(params.get("idCard")) && !checkUtil.isIDNumberValid(params.get("idCard").toString())){
			backMsg = "身份证号格式有误！";
		}
		return backMsg;
	}


	//获取列表数据
	@Override
	@Transactional
	public Map<String,Object> getExtraParam( String bid) throws Exception{
		Map<String,Object> entity = new ThrUserEntryApply()
				.addField("A.HeadUserId + '/' + U.UserName AS headUserName")
				.addField("O.DeptName AS deptName")
				.addField("R.Name AS roleName")
				.addField("BA1.HigherLevelPath + ',' + BA1.Name AS nativePlaceName")
				.addField("BA2.HigherLevelPath + ',' + BA2.Name AS workCityName")
				.addField("O1.OrgName AS belongCompanyName")
				.addField("B.VReMark AS officeName")
				.addField("B.VName AS officeTxt")
				//.addLeftJoin("YS_ProcInst P ON P.Bid = A.Bid ")
				.addLeftJoin("TS_OrganizationInfo O ON O.Orgid = A.DeptId AND 1=1")
				.addLeftJoin("TS_UserInfo U ON U.UserId = A.HeadUserId AND 1=1")
				.addLeftJoin("YS_Role R ON R.Id = A.RoleId AND 1=1")
				.addLeftJoin("TB_BaseInfoArea BA1 ON BA1.Code = A.NativePlace AND 1=1")
				.addLeftJoin("TB_BaseInfoArea BA2 ON BA2.Code = A.WorkCity AND 1=1")
				.addLeftJoin("TS_OrganizationInfo O1 ON O1.Orgid = A.BelongCompany AND 1=1")
				.addLeftJoin("TB_BaseInfo B ON B.Id = A.OfficeId AND 1=1")
				//.addLeftJoin("THR_OperateCompanyApply CA ON CA.VGsBm = A.BelongCompany AND 1=1")
				.setBid(bid)
				.queryFirstMap();
		//关联数据
		entity.put("roleIdAttribute", "职能");

		//获取用户照片数据
		List<ThrUserIdCardPhoto> thrUserIdCardPhoto = new ThrUserIdCardPhoto().setUserId(entity.get("userId").toString()).queryList();
		if(thrUserIdCardPhoto!=null ){
			if(thrUserIdCardPhoto.size()>=1){
				if(thrUserIdCardPhoto.get(0).getUserPhoto()!=null)entity.put("userPhoto1", thrUserIdCardPhoto.get(0).getUserPhoto());
				if(thrUserIdCardPhoto.get(0).getIdCardfront()!=null)entity.put("idCardfront1", thrUserIdCardPhoto.get(0).getIdCardfront());
				if(thrUserIdCardPhoto.get(0).getIdCardBack()!=null)entity.put("idCardBack1", thrUserIdCardPhoto.get(0).getIdCardBack());
			}
			if(thrUserIdCardPhoto.size()>=2){
				if(thrUserIdCardPhoto.get(1).getUserPhoto()!=null)entity.put("userPhoto2", thrUserIdCardPhoto.get(1).getUserPhoto());
				if(thrUserIdCardPhoto.get(1).getIdCardfront()!=null)entity.put("idCardfront2", thrUserIdCardPhoto.get(1).getIdCardfront());
				if(thrUserIdCardPhoto.get(1).getIdCardBack()!=null)entity.put("idCardBack2", thrUserIdCardPhoto.get(1).getIdCardBack());
			}
			if(thrUserIdCardPhoto.size()>=3){
				if(thrUserIdCardPhoto.get(2).getUserPhoto()!=null)entity.put("userPhoto3", thrUserIdCardPhoto.get(2).getUserPhoto());
				if(thrUserIdCardPhoto.get(2).getIdCardfront()!=null)entity.put("idCardfront3", thrUserIdCardPhoto.get(2).getIdCardfront());
				if(thrUserIdCardPhoto.get(2).getIdCardBack()!=null)entity.put("idCardBack3", thrUserIdCardPhoto.get(2).getIdCardBack());
			}
		}
		//获取审核时间
		YsProcInst ysProcInst = new YsProcInst().setBid(entity.get("bid").toString()).queryFirst();
		if(ysProcInst!=null && ysProcInst.getUpdateTime()!=null)entity.put("auditingTime", DateUtil.getYYYY_MM_DD_HH_mm_ss(ysProcInst.getUpdateTime()));

		return entity;
	}

}
